package com.bawei.demo_mvp.base;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

/**
 * @author yaotianxue
 * @description
 * @date 2025/5/12
 */
public abstract class BaseMvpActivity<V,P extends BasePresenter<V>>  extends AppCompatActivity implements BaseView {
    protected P mPresenter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(bindLayout());
        initView(savedInstanceState);
        mPresenter = createPresenter();
        initData();
        //绑定
        if(mPresenter != null){
            mPresenter.attachView((V) this); //解决内存泄漏问题
        }
    }


    public abstract int bindLayout();
    public abstract void initView(Bundle savedInstanceState);
    public abstract P createPresenter();//实例化presenter
    public abstract void initData();

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(mPresenter != null){
            mPresenter.distach(); //解决内存泄漏问题
        }
    }

}
